﻿Imports System.Net.Sockets
Imports System.Drawing.Imaging

Public Class Form1
    Dim Wc As New System.Net.WebClient



    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BUT_connex.Click
        Try
            Label1.Text = Wc.UploadString("http://" & TextBox3.Text & ":" & TextBox4.Text & "/get_status.cgi?user=" & TextBox1.Text & "&pwd=" & TextBox2.Text, "")
            VLC_player1.playlist.add("http://" & TextBox3.Text & ":" & TextBox4.Text & "/videostream.asf?user=" & TextBox1.Text & "&pwd=" & TextBox2.Text & "&resolution=32")
            VLC_player1.playlist.play()

        Catch ex As Exception
            Throw New Exception(ex.Message)
        End Try
    End Sub


    Private Sub Button2_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles BUT_up.MouseDown
        Try
            Wc.UploadString("http://" & TextBox3.Text & ":" & TextBox4.Text & "/decoder_control.cgi?user=" & TextBox1.Text & "&pwd=" & TextBox2.Text & "&command=0", "")
        Catch ex As Exception
            Throw New Exception(ex.Message)
        End Try

    End Sub

    Private Sub Button2_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles BUT_up.MouseUp
        Try
            Wc.UploadString("http://" & TextBox3.Text & ":" & TextBox4.Text & "/decoder_control.cgi?user=" & TextBox1.Text & "&pwd=" & TextBox2.Text & "&command=1", "")
        Catch ex As Exception
            Throw New Exception(ex.Message)
        End Try
    End Sub

    Private Sub BUT_down_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles BUT_down.MouseDown
        Try
            Wc.UploadString("http://" & TextBox3.Text & ":" & TextBox4.Text & "/decoder_control.cgi?user=" & TextBox1.Text & "&pwd=" & TextBox2.Text & "&command=2", "")
        Catch ex As Exception
            Throw New Exception(ex.Message)
        End Try
    End Sub

    Private Sub BUT_down_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles BUT_down.MouseUp
        Try
            Wc.UploadString("http://" & TextBox3.Text & ":" & TextBox4.Text & "/decoder_control.cgi?user=" & TextBox1.Text & "&pwd=" & TextBox2.Text & "&command=3", "")
        Catch ex As Exception
            Throw New Exception(ex.Message)
        End Try
    End Sub

    Private Sub BUT_left_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles BUT_left.MouseDown
        Try
            Wc.UploadString("http://" & TextBox3.Text & ":" & TextBox4.Text & "/decoder_control.cgi?user=" & TextBox1.Text & "&pwd=" & TextBox2.Text & "&command=4", "")

        Catch ex As Exception
            Throw New Exception(ex.Message)
        End Try
    End Sub

    Private Sub BUT_left_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles BUT_left.MouseUp
        Try
            Wc.UploadString("http://" & TextBox3.Text & ":" & TextBox4.Text & "/decoder_control.cgi?user=" & TextBox1.Text & "&pwd=" & TextBox2.Text & "&command=5", "")

        Catch ex As Exception
            Throw New Exception(ex.Message)
        End Try
    End Sub

    Private Sub BUT_right_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles BUT_right.MouseDown

        Try
            Wc.UploadString("http://" & TextBox3.Text & ":" & TextBox4.Text & "/decoder_control.cgi?user=" & TextBox1.Text & "&pwd=" & TextBox2.Text & "&command=6", "")

        Catch ex As Exception
            Throw New Exception(ex.Message)
        End Try
    End Sub

    Private Sub BUT_right_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles BUT_right.MouseUp

        Try
            Wc.UploadString("http://" & TextBox3.Text & ":" & TextBox4.Text & "/decoder_control.cgi?user=" & TextBox1.Text & "&pwd=" & TextBox2.Text & "&command=7", "")

        Catch ex As Exception
            Throw New Exception(ex.Message)
        End Try
    End Sub

    Private Sub BUT_deco_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BUT_deco.Click
        Try
            VLC_player1.playlist.stop()
        Catch ex As Exception
            Throw New Exception(ex.Message)
        End Try
    End Sub

    Private Sub BUT_status_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BUT_status.Click
        Try
            Label1.Text = Wc.UploadString("http://" & TextBox3.Text & ":" & TextBox4.Text & "/get_status.cgi?user=" & TextBox1.Text & "&pwd=" & TextBox2.Text, "")
        Catch ex As Exception
            Throw New Exception(ex.Message)
        End Try
    End Sub

    Private Sub BUT_params_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BUT_params.Click
        Try
            Label1.Text = Wc.UploadString("http://" & TextBox3.Text & ":" & TextBox4.Text & "/get_params.cgi?user=" & TextBox1.Text & "&pwd=" & TextBox2.Text, "")
        Catch ex As Exception
            Throw New Exception(ex.Message)
        End Try
    End Sub

    Private Sub BUT_checkuser_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BUT_checkuser.Click
        Try
            Try
                Label1.Text = Wc.UploadString("http://" & TextBox3.Text & ":" & TextBox4.Text & "/check_user.cgi?user=" & TextBox1.Text & "&pwd=" & TextBox2.Text, "")
            Catch ex As Exception
                If ex.Message.IndexOf("401") <> -1 Then
                    MessageBox.Show("Login ou mot de passe invalide", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                    Return
                Else
                    Throw New Exception(ex.Message)
                End If
            End Try
            BUT_connex.Visible = True
            BUT_deco.Visible = True

        Catch ex As Exception
            Throw New Exception(ex.Message)
        End Try
    End Sub



End Class
